/**
 * 
 */
package com.hand.cloud.b2b.taobao;

import java.util.concurrent.ConcurrentLinkedQueue;


public class TaskManager
{
	// 初始化队列（String是队列中的任务类型）
	public ConcurrentLinkedQueue<String> taskQueue = new ConcurrentLinkedQueue<String>();

	public void execute()
	{
		final AddTask addTask = new AddTask();
		final HandleTask HandleTask = new HandleTask();
		addTask.start();
		HandleTask.start();
	}

	public static void main(final String[] args)
	{
		final TaskManager taskM = new TaskManager();
		taskM.execute();

	}

	class AddTask extends Thread
	{
		long second2 = 2 * 1000;

		@Override
		public void run()
		{
			while (true)
			{
				// task为取到的任务
				final String task = String.valueOf(System.currentTimeMillis());
				taskQueue.add(task);

				// 将淘宝订单信息存入TB_OrderModel
				// .......

				try
				{
					Thread.sleep(second2);
				}
				catch (final InterruptedException e)
				{
					e.printStackTrace();
				}
			}
		}
	}

	class HandleTask extends Thread
	{

		long second4 = 4 * 1000;

		@Override
		public void run()
		{
			while (true)
			{


				// 将TB_OrderModel存入OrderModel
				// .......

				final String task = taskQueue.poll();
				if (task == null)
				{
					System.out.println("********");
					try
					{
						Thread.sleep(second4);
					}
					catch (final InterruptedException e)
					{
						e.printStackTrace();
					}
				}
				else
				{
					System.out.println(task);
				}
			}
		}
	}

}
